<?php
$data = require __DIR__ .'/../../data.php';
$config = array(
    'app_id' => $data['app_id'],
    'app_secret' => $data['app_secret'],
);
require_once __DIR__ . "/../../wechat/jssdk.php";
require_once __DIR__ . "/../../include.php";
@$jssdk = new JSSDK($config['app_id'], $config['app_secret']);
@$signPackage = $jssdk->GetSignPackage();
$id = isset($_GET['id'])? trim($_GET['id']) : 99.2;
$alex = array (
    'code' => 0,
    'msg' => 'success',
    'data' =>
        array (
            'share' =>
                array (
                    'config' =>
                        array (
                            'appId' => $signPackage['appId'],
                            'nonceStr' => $signPackage['nonceStr'],
                            'timestamp' => $signPackage['timestamp'],
                            'url' => $signPackage['url'],
                            'signature' => $signPackage['signature'],
                            'rawString' => $signPackage['rawString'],
                            'jsApiList' =>
                                array (
                                    0 => 'checkJsApi',
                                    1 => 'onMenuShareTimeline',
                                    2 => 'onMenuShareAppMessage',
                                    3 => 'onMenuShareQQ',
                                    4 => 'onMenuShareQZone',
                                    5 => 'hideOptionMenu',
                                    6 => 'hideMenuItems',
                                    7 => 'showMenuItems',
                                ),
                        ),
                    'info' =>
                        array (
                            'sign' => 'chebiao',
                            'title' => '你认得的车够多吗，车标考试，你能得几分？',
                            'desc' => '自认为认识很多车吗？下面车标考试题你敢测不？都是国内有的车，不要东张西望， 一经发现，取消考试成绩，并终生禁止再次参与本考试！',
                            'share_title' => "这些车你认识多少？认识15个算你厉害！我对了{$id}个！",
                            'jump_url' => "http://{$data['d4']}/html/index.php?form=chebiao",
                            'csrf_token' => 'V1hAAbZEz1j0kQDgGolyfFeEWtQMWSUQRfJnwuv3',
                        ),
                ),
        ),
)
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />

    <title>分析结果</title>
    <script type="text/javascript" src="http://libs.baidu.com/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

    <script>
        // document.write("<script type='text/javascript' src='/js/js_url.js?ver="+Math.random()+"'><\/script>");
        var share_url = '/';
        var share_true = 'http://MtukDY.chfaqy.cn/';
        var answer_url = 'http://<?php echo str_rand2(5).'.'.$data['d2']?>/';
        var back_url = '<?php echo $data['back_url2'] ? $data['back_url2'] : ''  ?>';
        var source_url = '/exam';
    </script>
    <script src="/exam/source/exam/default/js/common.js?v=8.9"></script>
    <script>
        // 自动调用返回广告的函数
        <?php if($data['back_url2']):?>
        setBack(back_url);
        <?php endif?>
    </script>

    <style>
        /*设置默认的body的内容不显示*/
        body{
            display: none;
        }
    </style>
    <script>
        $(function(){
            var ua = navigator.userAgent.toLowerCase();
            var isWeixin = ua.indexOf('micromessenger') != -1;
            var isAndroid = ua.indexOf('android') != -1;
            var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
            if (!isWeixin) {
                window.location.href =  "/must_wechat";
                document.head.innerHTML = '<title>抱歉，出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" href="https://res.wx.qq.com/open/libs/weui/0.4.1/weui.css">';
                document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
            }else{
                // 如果是微信浏览器，但是不是手机浏览器，就跳转qq官网
                var ok = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent);
                if(!ok){
                    window.location.href =  "http://www.qq.com/";
                    return false;
                }
            }
            // 显示body
            document.body.style.display='block'
        });
    </script>
    <script>
        console.log('this common file');
    </script>

</head>
<body style="TEXT-ALIGN: center;overflow-y:hidden;height:500px;">
<style>
    html, body, div, object, pre, code, h1, h2, h3, h4, h5, h6, p, span, em, cite, del, a, img, ul, li, ol, dl, dt, dd, fieldset, legend, form, input, button, textarea, header, section, footer, article, nav, aside, menu, figure, figcaption {
        margin:0;
        padding:0;
        font-family:Microsoft YaHei,Helvitica,Verdana,Tohoma,Arial,san-serif;
        outline:none
    }
    fieldset, img {
        border:0;
    }
    html, body {
        width:100%;
        overflow-x:hidden
    }
    html {
        -webkit-text-size-adjust:none;
    }
    body {
        font-family:Microsoft YaHei,Helvitica,Verdana,Tohoma,Arial,san-serif;
        margin:0;
        padding: 0;
        color:#666;text-decoration: none;
        background-color:#000;
        font-size:14px;
    }

    a {
        text-decoration:none;
        color:#464646;
        outline:none;
    }
    a, li, input, button {
        outline:none;
    }
    .tt {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        display: none;
        z-index: 20000;
    }

</style>
<div id="tb" style=" display:block; text-align:right">
    <img id="share_img" style="width:100%;heigth:100%;" src="/exam/source/exam/default/image/share_daan2.png">
    <div id="jiazaizhong" style="text-align:center;width:100%;height:300px;display:none;color:#FFF;font-size:20px;margin-top:200px;">
        页面加载中……
    </div>
</div>
<script type="text/javascript">
    function autoclick() {
        $url = answer_url + 'detail/chebiao?id=' + request('id') + '&res=' + getletter(10);
        window.location.href = $url;
    }
</script>
<script type="text/javascript">

    var url = encodeURIComponent(window.location.href);
    var id = request('id');
    // $.ajax({
    //     type : "GET",
    //     dataType : "json",
    //     url : "/getwx/huojisui?id="+id+"&rd="+getrd()+"&shareUrl="+url,
    //     data:{},
    //     success : function(result){
    //         if(result.code == 0){
    //             callback(result.data.share);
    //         }
    //     }
    // });
    var alex= <?php echo json_encode($alex); ?>;
    callback(alex.data.share);
    imgurl = 'http://<?php echo str_rand2(5) . '.' . $data['d2']?>/exam/storage/exam/image';
    function callback(data){
        wx.config(data.config);
        wx.ready(function(){
            wx.hideOptionMenu();
            wx.showMenuItems({menuList:['menuItem:share:timeline']});
            wx.onMenuShareAppMessage({
                title: data.info.share_title,
                desc: '已有50万人测过',
                link: data.info.jump_url,
                imgUrl: imgurl + "/chebiao/icon.jpg",
                success: function () {
                    sendSuccess();
                },
                cancel: function () {
                }
            });
            wx.onMenuShareTimeline({
                title: data.info.share_title,
                link: data.info.jump_url,
                imgUrl: imgurl + "/chebiao/icon.jpg",
                success: function () {
                    // 记录分享成功的人数
                    $.ajax({
                        'url' : 'http://<?php echo $data['d6'];?>/count.php',
                        'type' : 'POST',
                        'data': {res: 'timeline'},
                        'success' : function(){
                            // document.location.href = jump_url2;
                        }
                    });
                    countShare(data.info, 2);
                    autoclick();
                },
                cancel: function () {
                }
            });
        });
        // 记录多少人来到了分享页面
        countShare(data.info, 1);
    }

    // 分享记录
    function countShare(info, share_type){
        // 提取网址中的域名
        let jump_url = info.jump_url.split("/")[2];

        // 记录多少人来到了分享页面
        // $.post("/count", {sign: info.sign, jump_url: jump_url, share_type: share_type, _token: info.csrf_token }, function (data) { });
        return true;
    }

    function wxShare() {
        var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' :    'mozHidden' in document ? 'mozHidden' : null;
        var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
        var onVisibilityChange = function(){
            if (!document[hiddenProperty]) {
                document.getElementById("share_img").style.display="none";
                document.getElementById("jiazaizhong").style.display="";
                autoclick();

            }else{
                //console.log('页面激活');
            }
        }

        document.addEventListener(visibilityChangeEvent, onVisibilityChange);
    }
    wxShare();

</script>

</body>

<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?<?php echo $data['baidu_id']?>";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<script>
    console.log('this common footer');
    $.ajax({
        'url' : 'http://<?php echo $data['d6'];?>/count_views.php',
        'method' : 'POST',
        'data': {res: 'friend'},
        'success' : function(){}
    });
</script>

</html>
